package com.ruoyi.health.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.health.domain.NoticeCategory;
import com.ruoyi.health.service.INoticeCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 资讯分类Controller
 * 
 * @author dalian
 * @date 2023-08-05
 */
@RestController
@RequestMapping("/health/healthNoticeCategory")
public class NoticeCategoryController extends BaseController
{
    @Autowired
    private INoticeCategoryService noticeCategoryService;

    /**
     * 查询资讯分类列表【8.7已完成】
     */
    // @PreAuthorize("@ss.hasPermi('health:healthNoticeCategory:list')")
    @GetMapping("/list")
    public AjaxResult list(NoticeCategory noticeCategory)
    {
        List<NoticeCategory> list = noticeCategoryService.selectNoticeCategoryList(noticeCategory);
        return success(list);
    }

    /**
     * 导出资讯分类列表
     */
    @PreAuthorize("@ss.hasPermi('health:healthNoticeCategory:export')")
    @Log(title = "资讯分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NoticeCategory noticeCategory)
    {
        List<NoticeCategory> list = noticeCategoryService.selectNoticeCategoryList(noticeCategory);
        ExcelUtil<NoticeCategory> util = new ExcelUtil<NoticeCategory>(NoticeCategory.class);
        util.exportExcel(response, list, "资讯分类数据");
    }

    /**
     * 根据id获取资讯分类信息 【8.7已完成】
     */
    @PreAuthorize("@ss.hasPermi('health:healthNoticeCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(noticeCategoryService.selectNoticeCategoryById(id));
    }

    /**
     * 新增资讯分类【8.7已完成】
     */
    @PreAuthorize("@ss.hasPermi('health:healthNoticeCategory:add')")
    @Log(title = "资讯分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NoticeCategory noticeCategory)
    {
        noticeCategory.setCreateBy(getUsername());  //添加createBy
        return toAjax(noticeCategoryService.insertNoticeCategory(noticeCategory));
    }

    /**
     * 修改资讯分类【8.7已完成】
     */
    @PreAuthorize("@ss.hasPermi('health:healthNoticeCategory:edit')")
    @Log(title = "资讯分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NoticeCategory noticeCategory)
    {
        return toAjax(noticeCategoryService.updateNoticeCategory(noticeCategory));
    }

    /**
     * 删除资讯分类 【8.7已完成】
     */
    @PreAuthorize("@ss.hasPermi('health:healthNoticeCategory:remove')")
    @Log(title = "资讯分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(noticeCategoryService.deleteNoticeCategoryById(id));
    }
}
